//
//  RegisterViewController.m
//  ManageMoney
//
//  Created by epwk on 15/9/15.
//  Copyright (c) 2015年 db. All rights reserved.
//

#import "RegisterViewController.h"

#define kAlphaNum   @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

@interface RegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *registerCodeField;//注册码
@property (weak, nonatomic) IBOutlet UITextField *userNameField;//用户名
@property (weak, nonatomic) IBOutlet UITextField *pwdField;//登录密码
@property (weak, nonatomic) IBOutlet UITextField *pwdConfirmationField;//登录 密码确认
@property (weak, nonatomic) IBOutlet UITextField *TransactionPwd;//交易密码
@property (weak, nonatomic) IBOutlet UITextField *TransactionPwdConfirmation;//确认交易密码
@property (weak, nonatomic) IBOutlet UITextField *realNameField;//真是姓名
@property (weak, nonatomic) IBOutlet UITextField *userIdCard;//身份证
@property (weak, nonatomic) IBOutlet UITextField *mobilePhone;//手机号
@property (weak, nonatomic) IBOutlet UITextField *phoneCode;//验证码

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"注册";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - textField delegate

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == _mobilePhone) {
        
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string {
    //限制身份证号  只能输字母和数字
    if (textField == _userIdCard) {
        NSCharacterSet *cs;
        cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
        NSString *filtered =
        [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        BOOL basic = [string isEqualToString:filtered];
        return basic;
    }
    
    return YES;
}


#pragma mark - RequestAction 注册
-(void)requestRegisterWithParams:(NSDictionary *)pramas
{
    
    [[AFNetApiClient sharedClient] requestRegisterWithParams:pramas success:^(AFHTTPRequestOperation *operation , id responseObject) {
        NSDictionary *dic = responseObject;
        if ([dic[@"responseCode"] intValue] == 200) {
            [SVProgressHUD showSuccessWithStatus:@"登录成功"];
            

            
        }else
        {
            [SVProgressHUD showErrorWithStatus:dic[@"responseMessage"]];
        }
    } failure:^(AFHTTPRequestOperation *operation , NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

#pragma mark - RequestAction 登录
-(void)requestLoginWithParams:(NSDictionary *)pramas
{
    
    [[AFNetApiClient sharedClient] requestLoginWithParams:pramas success:^(AFHTTPRequestOperation *operation , id responseObject) {
        NSDictionary *dic = responseObject;
        if ([dic[@"responseCode"] intValue] == 200) {
            [SVProgressHUD showSuccessWithStatus:@"登录成功"];
            
            NSDictionary *userDic = dic[@"data"];
            [UserDefaults setObject:userDic forKey:kUserInfo];
            [UserDefaults setBool:YES forKey:kDidLogin];
            [UserDefaults synchronize];
            

            
            [[NSNotificationCenter defaultCenter] postNotificationName:RefreshUserData object:dic[@"data"]];
            [self leftBarButtonClick:nil];
            
        }else
        {
            [SVProgressHUD showErrorWithStatus:dic[@"responseMessage"]];
        }
    } failure:^(AFHTTPRequestOperation *operation , NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
